unit dmsc_EnergyMaster;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dmModule, FR_DSet, FR_DBSet, DB, ADODB;

type
  Tdtmsc_EnergyMaster = class(TdtmModule)
    adsDetail: TADODataSet;
    adsMasterHasCheck: TBooleanField;
    adsMasterChecker: TStringField;
    adsMasterCheckTime: TDateTimeField;
    adsMasterWriter: TStringField;
    adsMasterWriteTime: TDateTimeField;
    adsMasterModifier: TStringField;
    adsMasterModifyTime: TDateTimeField;
    adsMasterRemark: TStringField;
    adsDetailWriter: TStringField;
    adsDetailWriteTime: TDateTimeField;
    adsDetailModifier: TStringField;
    adsDetailModifyTime: TDateTimeField;
    adsDetailRemark: TStringField;
    adsMasterEditHasCheck: TBooleanField;
    adsMasterEditChecker: TStringField;
    adsMasterEditCheckTime: TDateTimeField;
    adsMasterEditWriter: TStringField;
    adsMasterEditWriteTime: TDateTimeField;
    adsMasterEditModifier: TStringField;
    adsMasterEditModifyTime: TDateTimeField;
    adsMasterEditRemark: TStringField;
    adsMasterEditBillID: TStringField;
    adsMasterEditBillNo: TStringField;
    adsMasterEditBillDate: TDateTimeField;
    adsMasterEditBillType: TStringField;
    adsMasterBillID: TStringField;
    adsMasterBillNo: TStringField;
    adsMasterBillDate: TDateTimeField;
    adsMasterBillType: TStringField;
    adsDetailID: TStringField;
    adsDetailBillID: TStringField;
    adsDetailProcessDate: TDateTimeField;
    adsDetaildye_Water: TBCDField;
    adsDetaildye_Electric: TBCDField;
    adsDetaildye_Vapor: TBCDField;
    adsDetailFix_Water: TBCDField;
    adsDetailFix_Electric: TBCDField;
    adsDetailFix_Vapor: TBCDField;
    adsDetailWash_Water: TBCDField;
    adsDetailWash_Electric: TBCDField;
    adsDetailWash_Vapor: TBCDField;
    adsDetailWaterSum: TBCDField;
    adsDetailElectricSum: TBCDField;
    adsDetailVaporSum: TBCDField;
    procedure adsDetailNewRecord(DataSet: TDataSet);
    procedure adsDetailBeforePost(DataSet: TDataSet);
    procedure adsDetaildye_WaterChange(Sender: TField);
  private
    { Private declarations }
    procedure CalceFieldData(DataSet: TDataSet);
  protected
    procedure ModuleInit;override;
  public
    { Public declarations }
    procedure OpenEditDataSet;override;
  end;

var
  dtmsc_EnergyMaster: Tdtmsc_EnergyMaster;

implementation

{$R *.dfm}

{ Tdtmsc_EnergyMaster }

procedure Tdtmsc_EnergyMaster.ModuleInit;
begin
  inherited;
  FUniqueTable := 'sc_EnergyMaster';
end;

procedure Tdtmsc_EnergyMaster.adsDetailNewRecord(DataSet: TDataSet);
begin
  inherited;
  SetWriteInfo(DataSet);
end;

procedure Tdtmsc_EnergyMaster.adsDetailBeforePost(DataSet: TDataSet);
begin
  inherited;
  SetModifyInfo(DataSet);
end;

procedure Tdtmsc_EnergyMaster.OpenEditDataSet;
begin
  FMasterEditTable := 'sc_EnergyMaster';
  FMasterKeyField := 'BillID';
  inherited;

end;

procedure Tdtmsc_EnergyMaster.CalceFieldData(DataSet: TDataSet);
begin
  if (adsDetail.State in [dsInsert, dsEdit]) then
  begin
    DataSet.FieldByName('WaterSum').ReadOnly := False;
    DataSet.FieldByName('WaterSum').AsFloat := DataSet.FieldByName('dye_Water').AsFloat
      + DataSet.FieldByName('Fix_Water').AsFloat + DataSet.FieldByName('Wash_Water').AsFloat;
    DataSet.FieldByName('ElectricSum').ReadOnly := False;
    DataSet.FieldByName('ElectricSum').AsFloat := DataSet.FieldByName('dye_Electric').AsFloat
      + DataSet.FieldByName('Fix_Electric').AsFloat + DataSet.FieldByName('Wash_Electric').AsFloat;
    DataSet.FieldByName('VaporSum').ReadOnly := False;
    DataSet.FieldByName('VaporSum').AsFloat := DataSet.FieldByName('dye_Vapor').AsFloat
      + DataSet.FieldByName('Fix_Vapor').AsFloat + DataSet.FieldByName('Wash_Vapor').AsFloat;
  end;
end;

procedure Tdtmsc_EnergyMaster.adsDetaildye_WaterChange(Sender: TField);
begin
  inherited;
  CalceFieldData(adsDetail);
end;

end.
